<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@taglib uri="/WEB-INF/fmt.tld" prefix="fmt"%>
<%@taglib uri="/WEB-INF/fn.tld" prefix="fn"%>
<%@taglib uri="/WEB-INF/el.tld" prefix="el"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<c:import url="/includes/css_inc.jsp"/>
		<c:import url="/includes/js_inc.jsp"/>
		<script>
			$(function(){
		        $("#search").button({
		            icons: {
		                primary: "ui-icon-search"
		            }
		        }).click(function(){
		        	dateFormat(document.getElementById("startDate"));
		        	dateFormat(document.getElementById("endDate"));
		        	var result = "";
					if(validateEmpty()){
			        	result = dateDiff($("#startDate").val(), $("#endDate").val(),"/");
			        	if (!result) {
			        		alert("วันเริ่มต้นต้องน้อยกว่าวันสิ้นสุดกรุณาระบุใหม่");
			        		$("#endDate").val("");
							return false;
			        	} else {
							$("#searchForm").submit();
						}
					} else {
						return false;
					}
				});
		        $("#download").button({
		            icons: {
		                primary: "ui-icon-arrowthickstop-1-s"
		            }
		        }).click(function(){
		        	dateFormat(document.getElementById("startDate"));
		        	dateFormat(document.getElementById("endDate"));
		        	var result = "";
					if(validateEmpty()){
			        	result = dateDiff($("#startDate").val(), $("#endDate").val(),"/");
			        	if (!result) {
			        		alert("วันเริ่มต้นต้องน้อยกว่าวันสิ้นสุดกรุณาระบุใหม่");
			        		$("#endDate").val("");
							return false;
			        	} else {
			        		window.location='/provacc/acc6?app=ACC60103&job=export&provinceId='+$("#provinceId").val()+'&startDate='+$("#startDate").val()+'&endDate='+$("#endDate").val();
						}
					} else {
						return false;
					}
				});
		        thaiDatepicker("startDate","#","1");
		        thaiDatepicker("endDate","#","1");
			});
		</script>
	</head>
	<body>
		<c:import url="/apps/msg.jsp"/>
		<form class="acc67-form" name="searchForm" id="searchForm" action="${pageContext.request.contextPath}/acc6" method="post">
		<input type="hidden" name="app" id="app" value="ACC60103"/>
		<input type="hidden" name="job" id="job" value="search"/>
		<table width="100%" class="ui-widget ui-widget-content" border="0">
			<tr>
				<th align="left" class="acc67-header ui-widget-header" colspan="2"><b>${screenCode.ACC60103}</b></th>
			</tr>
			<tr>
				<td width="20%" class="bold">จังหวัด : </td>
				<td>
					<c:if test="${userInfo.areaLevel =='3'}">
						<c:forEach var="data" items="${userInfo.listUserProvice}">
							${data.provinceName}
							<input type="hidden" name="provinceId" id="provinceId" value="${data.provinceId}">
						</c:forEach>
					</c:if>
					<c:if test="${userInfo.areaLevel=='1' || userInfo.areaLevel=='2'}">
						<select name="provinceId" id="provinceId">
							<c:if test="${'all' == provinceId}" var="provinceSeleted"/>
							<option value="all" ${provinceSeleted?'selected':''}>เลือกทั้งหมด</option>
							<c:forEach var="data" items="${userInfo.listUserProvice}">
								<c:if test="${data.provinceId == provinceId}" var="provinceSeleted"/>
								<option value="${data.provinceId}" ${provinceSeleted?'selected':''}>${data.provinceName}</option>
							</c:forEach>
						</select>
					</c:if>
				</td>
			</tr>
			<tr>
				<td width="20%" class="bold">วันเริ่มต้น : </td>
				<td>
					<input type="text" name="startDate" id="startDate" size="12" maxlength="10" onkeypress="return numberAndSlash(event);" onblur="dateFormat(this);" value="${startDate}"/>
					<span id="#startDate" class="red">*</span>
				</td>
			</tr>
			<tr>
				<td class="bold">วันสิ้นสุด : </td>
				<td>
					<input type="text" name="endDate" id="endDate" size="12" maxlength="10" onkeypress="return numberAndSlash(event);" onblur="dateFormat(this);" value="${endDate}"/>
					<span id="#endDate" class="red">*</span>	
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					<button type="submit" name="search" id="search" class="acc67-button"> ค้นหาข้อมูล </button>
					<button type="button" name="download" id="download" class="acc67-button"> Download </button>
				</td>
			</tr>
		</table>
		<br/>
		<c:if test="${!empty pageBean.pageData}">
			<fieldset>
				<legend> ผลการค้นหาข้อมูล </legend>
				<table width="100%" class="acc67-grid ui-widget ui-widget-content">
					<tr>
						<td align="right" colspan="5">ยอดรวมทั้งหมด</td>
						<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumAmount}" /></td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'REF_NO');"><span id="REF_NO" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>เลขที่เอกสาร</th>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'BUDGET_YEAR');"><span id="BUDGET_YEAR" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>ปีงบประมาณ</th>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'INCOME_DATE');"><span id="INCOME_DATE" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>วันที่รับโอน</th>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'VENDER_CODE');"><span id="VENDER_CODE" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>สปสช.สาขาจังหวัด</th>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'ALLOCATE_CODE');"><span id="ALLOCATE_CODE" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>กองทุนย่อยเฉพาะด้าน</th>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'INCOME_AMOUNT');"><span id="INCOME_AMOUNT" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>จำนวนเงิน</th>
						<th align="center" class="ui-state-default" onclick="pageControl('S', 'TRANSACTION_TIMESTAMP');"><span id="TRANSACTION_TIMESTAMP" class="ui-icon ui-icon-triangle-2-n-s" style="float: right;"></span>เลขที่เอกสารอ้างอิงจาก sap</th>
					</tr>
						<c:forEach var="data" items="${pageBean.pageData}" varStatus="x">
							<tr class="grid-tr-${x.count % 2}">
								<td align="center">${data.refNo}</td>
								<td align="center">${data.budgetYear}</td>
								<td align="center">${el:dateTh(data.incomeDate)}</td>
								<td align="left">${el:getDataUtil('PAN', data.provinceId)}</td>
								<c:if test="${!empty data.allocateCode}">
									<td align="left">${data.allocateCode} - ${el:getDataUtil('AN', data.allocateCode)}</td>
								</c:if>
								<c:if test="${empty data.allocateCode}">
									<td align="left"></td>
								</c:if>
								<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmount}" /></td>
								<td align="center">${data.transactionTimestamp}</td>
							</tr>
						</c:forEach>
				<!-- 	<tr>
						<td colspan="5">ยอดรวม</td>
						<td></td>
					</tr> -->
					<input type="hidden" name="formPage" id="formPage" value="searchForm"/>
					<c:import url="/apps/page.jsp"/>
				</table>
			</fieldset>
		</c:if>
		</form>
		
	</body>
</html>